

//首页的一个大的接口
import 'package:flutter_trip_demo/model/sales_box_model.dart';

import 'common_model.dart';
import 'config_model.dart';
import 'gridview_navigator_model.dart';

class HomeModel {
  //实例化configmodel
  final ConfigModel configModel;

  //bannerlist
  final List<CommonModel> bannerList;

  //sub
  final List<CommonModel> subNavList;

  //homeNavlist
  final List<CommonModel> localNavList;

  //网格了里面的内容
  final GridNavModel gridVav;

  //热卖
  final SalesBoxModel salesBox;

  //构造方法
  HomeModel(
      {required this.configModel,
      required this.bannerList,
      required this.subNavList,
      required this.localNavList,
      required this.gridVav,
      required this.salesBox});

  /*
  * 创建工厂方法
  * ******************************************************************
  * map主要是进行遍历
  * */

  factory HomeModel.fromJson(Map<String, dynamic> json) {

    var localNavListJson = json['localNavList'] as List;
    List<CommonModel> localNavList =
    localNavListJson.map((i) =>
        CommonModel.fromJson(i)).toList();


    var bannerListJson = json['bannerList'] as List;
    List<CommonModel> bannerList =
    bannerListJson.map((i) =>
        CommonModel.fromJson(i)).toList();
    // print(bannerList);

    var subNavListJson = json['subNavList'] as List;
    List<CommonModel> subNavList =
    subNavListJson.map((i) =>
        CommonModel.fromJson(i)).toList();
    // print(subNavList);

    return HomeModel(
      configModel: ConfigModel.fromJson(json['config']),
      bannerList: bannerList,
      subNavList: subNavList,
      localNavList: localNavList,
      gridVav: GridNavModel.fromJson(json['gridNav']),
      salesBox: SalesBoxModel.fromJson(json['salesBox']),
    );
  }
}
